﻿using Senparc.Weixin.MP.CommonAPIs;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using VTemplate.Engine;
using MxWeiXinPF.Common;

namespace MxWeiXinPF.Web
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            log4net.Config.XmlConfigurator.Configure(new FileInfo(Server.MapPath("~/Web.config")));

            Model.wx_userweixin weixin = new MxWeiXinPF.BLL.wx_userweixin().GetModel(39);
            if (weixin == null)
            {
                return;
            }
            if (!AccessTokenContainer.CheckRegistered(weixin.AppId))
            {
                AccessTokenContainer.Register(weixin.AppId, weixin.AppSecret);
            }
            BLL.express expressBll = new BLL.express();
            List<Model.express> expModel = expressBll.GetModelList("");
            GlobalCacheHelper.Insert("express_models", expModel);

            //支付方式
            BLL.payment pbll = new BLL.payment();
            Model.payment payModel = pbll.GetModelBypTypeId(3);
            GlobalCacheHelper.Insert("pay_models", payModel);
            //运费
            Model.wx_shop_setting msetting = new BLL.wx_shop_setting().GetModel(5);
            GlobalCacheHelper.Insert("yunfei", msetting);

            BLL.wx_payment_wxpay wxBll = new BLL.wx_payment_wxpay();
            Model.wx_payment_wxpay wxpay = wxBll.GetModelByWid(39);
            GlobalCacheHelper.Insert("wx_pay", wxpay);

            GlobalCacheHelper.Insert("weixin", weixin);
            VTemplateMgr tm = new VTemplateMgr();
            tm.Init(Server.MapPath("~/Web.config"));
        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}